//
//  UIBarButtonItem+Extension.swift
//  Weibo
//
//  Created by 崔健 on 16/5/21.
//  Copyright © 2016年 cbj. All rights reserved.
//

import UIKit

extension UIBarButtonItem{

    convenience init(imageName:String , title : String , target : UIViewController , action : Selector) {
        
        self.init()
        let btn = UIButton()
        
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -8, bottom: 0, right: 0)
        btn.setImage(UIImage.init(named: imageName), forState: .Normal)
        btn.setImage(UIImage.init(named: imageName + "_highlighted"), forState: .Highlighted)
        
        btn.sizeToFit()
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        self.customView = btn
    }
}
